/*
 * @Author: silence silence9685@163.com
 * @Date: 2023-04-21 11:37:03
 * @LastEditors: silence silence9685@163.com
 * @LastEditTime: 2023-07-31 16:45:13
 * @FilePath: \lenercom_bluetooth_app\lib\pages\Mine\AccountManager\View\AMTitleView.dart
 * @Description: 设置-item-内容
 */
import 'package:ems_neutral_app/common/widgets/cubitWidget/DividingLine.dart';
import 'package:flutter/material.dart';
import 'package:sil_base_widget_package/sil_base_widget_package.dart';

import '../../../utils/color/ColorUtils.dart';

class SettingItem extends StatelessWidget {
  final String? title;

  /// 左侧图片
  final String? leftImgPath;

  /// 左侧图片宽度，默认24
  final double? leftImgWidth;
  final double? leftImgHeight;

  final String? subTitle;
  final EdgeInsets? margin;

  /// 是否隐藏右侧箭头，默认不隐藏
  final bool? hideRightArrow;
  final void Function()? onTapFunc;

  /// 右侧显示的View
  final Widget? rightView;
  final double? titleFontSize;
  final FontWeight? titleFontWidget;

  final double? lineHorizontalSpace;

  /// 是否隐藏底部分割线,默认显示
  final bool dividingLineHide;

  const SettingItem(
      {required this.title,
      this.leftImgPath,
      this.leftImgWidth,
      this.leftImgHeight,
      this.subTitle,
      this.margin,
      this.hideRightArrow = false,
      this.onTapFunc,
      this.rightView,
      this.titleFontSize,
      this.titleFontWidget,
      this.lineHorizontalSpace,
      this.dividingLineHide = false,
      Key? key})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return SilEmptyButton(
      useConstrained: true,
      onTapFunc: this.onTapFunc,
      child: Stack(
        alignment: Alignment.center,
        children: [
          Container(
            child: contentView(),
            padding: this.margin ??
                EdgeInsets.symmetric(vertical: 15.w, horizontal: 20.w),
          ),
          if (this.dividingLineHide == false)
            Positioned(
              child: DividingLine(
                  margin: EdgeInsets.symmetric(
                      horizontal: this.lineHorizontalSpace ?? 20.w)),
              bottom: 0,
              left: 0,
              right: 0,
            )
        ],
      ),
    );
  }

  contentView() {
    return Row(
      mainAxisAlignment: MainAxisAlignment.spaceBetween,
      children: [
        /// 左边内容
        Container(child: leftView(), margin: EdgeInsets.only(right: 5.w)),

        /// 右侧内容
        Expanded(child: this.rightView ?? righView())
      ],
    );
  }

  leftView() {
    return Row(
      children: [
        /// 左侧图片
        if (this.leftImgPath != null)
          SilImage(
            this.leftImgPath,
            width: this.leftImgWidth ?? 24.w,
            height: this.leftImgHeight ?? 24.w,
            margin: EdgeInsets.only(right: 10.w),
          ),

        /// 左边标题
        SilText(this.title,
            fontSize: this.titleFontSize ?? 16.sp,
            color: ColorUtils.color_font_main,
            fontWeight: this.titleFontWidget ?? FontWeight.w500,
            textAlign: TextAlign.left),
      ],
    );
  }

  righView() {
    return Row(
      mainAxisAlignment: MainAxisAlignment.end,
      children: [
        if (this.subTitle != null)
          Expanded(child: SilText(this.subTitle,
              fontSize: 14.sp,
              color: ColorUtils.color_font_minor,
              textAlign: TextAlign.right)),
        // 右侧箭头
        if (this.hideRightArrow == false)
          Container(
              margin: EdgeInsets.only(left: 10.w),
              width: 24.w,
              height: 24.w,
              child: SilImage('imgs/personal/list_icon_arrow@3x.png'))
      ],
    );
  }
}
